import 'package:s_mankey/config/net/api.dart';
import 'package:s_mankey/model/home_article_model.dart';
import 'package:s_mankey/model/home_audio_model.dart';
import 'package:s_mankey/model/home_banner_model.dart';
import 'package:s_mankey/provider/view_state_model.dart';
import 'package:s_mankey/service/smonkey_repository.dart';

/// Banner视图模型
class HomeDataVModel extends ViewStateModel {
  var datas;
  var banner;
  var audio;
  var ariticle;
  var enterprise;
  var course;
  bool showLoading = true;

  initData() async {
    setBusy();
    try {
      List<Future> futures = [];

      futures
        ..add(SmonkeysRepository.fetchHomeBanner())
        ..add(SmonkeysRepository.fetchHomenAudio())
        ..add(SmonkeysRepository.fetchHomeArticle())
        ..add(SmonkeysRepository.fetchHomeIntegrityHot())
        ..add(SmonkeysRepository.fetchHomeCourse(city: 'KM', lang: 's'));

      /// 下标分别对应上面的请求顺序.
      datas = await Future.wait(futures);
      if(datas.length >= 4) showLoading = false;
      banner = datas[0]['list'];
      audio = datas[1];
      ariticle = datas[2];
      enterprise = datas[3];
      course = datas[4];

      setIdle();
    } catch (e, s) {
      setError(e, s);
    }
  }
}
